package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.dto.UserDTO;
import cn.edu.nit.sys.entity.User;
import cn.edu.nit.sys.service.UserService;
import cn.edu.nit.sys.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public R getList(Page<UserDTO> page, String name, String role) {
        log.info("查询用户，入参：{}, {}, {}", page.getSize(), page.getPages(), role);
        return userService.getList(page, name, role);
    }

    @PutMapping("/phone")
    public R updateUserPhone(@RequestBody Map<String, String> params) {
        return userService.updateUserPhone(params);
    }

    @PutMapping("/password")
    public R updatePassword(@RequestBody Map<String, String> params) {
        return userService.updatePassword(params);
    }

    @PutMapping
    public R updateInfo(@RequestBody Map<String, String> params) {
        return userService.updateInfo(params);
    }

    @GetMapping("/base/{id}")
    public R baseData(@PathVariable("id") String id) {
        return userService.baseData(id);
    }

    @GetMapping("/check")
    public R checkFans(String uid, String id) {
        return userService.checkFans(uid, id);
    }

    @PostMapping("/fans")
    public R updateFans(@RequestBody Map<String, String> params) {
        String uid = params.get("uid");
        String id = params.get("id");
        return userService.updateFans(uid, id);
    }

    @GetMapping("/clazz")
    public R getClazzUser(String id) {
        return userService.getClazzUser(id);
    }

    @GetMapping("/attention")
    public R getAttentionUser(Page<Map<String, String>> page, String id) {
        return userService.getAFUserList(page, id, "0");
    }

    @GetMapping("/fans")
    public R getFansUser(Page<Map<String, String>> page, String id) {
        return userService.getAFUserList(page, id, "1");
    }
}
